package com.anxinr.filter;


import com.anxinr.config.RequestBodyWrapper;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤器  放入自定义的请求体
 * @author : anxinr
 * @date : 2022/10/11 14:41
 */
@Component
public class ProjectFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if(servletRequest instanceof HttpServletRequest){
            filterChain.doFilter(new RequestBodyWrapper((HttpServletRequest) servletRequest), servletResponse);
        }else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
